﻿using B.S.Base.Write.API.Application.Command;
using MediatR;
using WEBAPI.Damoin;
using WEBAPI.ErroeCode;
using WEBAPI.Indaseture.Infasetures;

namespace B.S.Base.Write.API.CommandHandLer
{
    public class DeltetAccountCommandHandLer : IRequestHandler<DeleteaccountCommand, APIResult<object >>
    {
      private readonly  IBaseRepostiy<AccountModel> _accountmodel;

        public DeltetAccountCommandHandLer(IBaseRepostiy<AccountModel> accountmodel)
        {
            this._accountmodel = accountmodel;
        }

        public async Task<APIResult<object>> Handle(DeleteaccountCommand request, CancellationToken cancellationToken)
        {
            var list = _accountmodel.GetAll().FirstOrDefault(x =>x.AccountId == request.AccountId);
            list.IsDeleted = true;
            await _accountmodel.Update(list);
            return new APIResult<object>()
            {
                Code = ResultCode.Ok,
                Message = "删除成功",
                Data = 1,
            };
        }
    }
}
